﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.IO;
namespace CricketHub
{
    public class TeamRequestingData
    {
        HttpWebRequest request;
        public Teams team;
        public void Request()
        {
            try
            {
                request = (HttpWebRequest)WebRequest.Create("http://www.myworkdemos.com/sports/CricketProfiles/TeamData.php");//http://lifeh2o.freevar.com/teamprofiles.xml");
                IAsyncResult result = (IAsyncResult)request.BeginGetResponse(new AsyncCallback(Resp), this);
            }
            catch (Exception kk)
            {
                Deployment.Current.Dispatcher.BeginInvoke(() =>
                    {
                        MessageBox.Show("Please check the network connection");
                    });
            }
 
        }
        public void Resp(IAsyncResult asyn)
        {
            try
            {
                TeamRequestingData team_obj = (TeamRequestingData)asyn.AsyncState;
                HttpWebRequest request2 = request;
                HttpWebResponse response = (HttpWebResponse)request2.EndGetResponse(asyn);
                Stream streamdata = response.GetResponseStream();
                StreamReader reader = new StreamReader(streamdata);
                string team_data = reader.ReadToEnd();

                team.Update(team_data);
            }
            catch (Exception kkk)
            {
                Deployment.Current.Dispatcher.BeginInvoke(() =>
                {
                    MessageBox.Show("Please check the network connection");
                });
 
            }

        }

    }
}
